import { ITimer } from "../../api/timer/ITimer";
import { TimerUtils } from "../../api/timer/TimerUtils";
import { E_TimeConfig } from "../defs/com/E_TimeConfig";
import { Player } from "../struct/Player";


/**
 * 数据-服务器信息
 */
export abstract class SDServer {

    /**
     * 开服时间
     * @param player 
     */
    public static getServerCreateTime(player: Player): number {
        if (player) {
            return player.server.createTime;
        }
        return 0;
    }


    /**
     * 过去的时间
     * @param player 
     * @param now 
     */
    public static getPassDay(
        player: Player,
        now = ITimer.getServerTime()
    ): number {
        const creatTime = this.getServerCreateTime(player);
        const ct = TimerUtils.getDayZeroTime(creatTime);
        const nt = TimerUtils.getDayZeroTime(now);
        const day = Math.floor((nt - ct) / E_TimeConfig.Day);
        return day;
    }


    /**
     * 一周里边的第几天
     * @param player 
     * @param now 
     * @returns 
     */
    public static getPassWeekDay(player: Player, now = ITimer.getServerTime()): number {
        const day = this.getPassDay(player, now);
        return day % 7;
    }



}
